<template>
  <input v-model="msg" />
  <hr />
  {{ msg }}
</template>
<script lang="ts">
import { customRef } from "vue";
export default {
  setup() {
    //自定义响应式函数，指定值value
    let myRef = function <T>(value: T) {
      return customRef((track, trigger) => {
        return {
          get() {
            track(); //通知vue追踪该变量
            return value;
          },
          set(newValue) {
            value = newValue;
            trigger(); //更新视图
          },
        };
      });
    };

    let msg = myRef("Hello");
    return { msg };
  },
};
</script>
